package com.bosssoft.hr.javase;

public class MyQueueEx {

    Student[] users1 = {
            new Student(1, "zhangsan"),
            new Student(2, "lisi"),
            new Student(3, "wangwu"),
            new Student(4, "zhaoliu"),
            new Student(5, "tianqi"),

    };

    public void testQueueAdd() throws Exception {
        Queue<Student> users = new MyQueue(5);
        // 使用add方法加入5个用户
        // 断言数量正确  否则抛出异常
        for (int i = 0; i < users1.length; i++) {
            users.add(users1[i]);
            System.out.println("add " + users1[i]);
        }
    }

    public void testQueueRemove() throws Exception {
        Queue<Student> users = new MyQueue(5);
        for (int i = 0; i < users1.length - 1; i++) {
            users.add(users1[i]);
            System.out.println("add " + users1[i].toString());
        }
        // 使用add方法加入5个用户
        //  循环6次删除poll队列首，断言第6次为false
        int size = 5; // == 5
        for (int i = 0 ; i < size + 1; i++) {
            Student poll = users.poll();
            if (poll == null) {
                System.out.println("队列中无元素");
            } else {
                System.out.println(poll);
            }

        }

    }

}
